import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store/index.js'

Vue.use(VueRouter)
const routes = [{
	path: '/',
	redirect: '/home',
},
{
	path: '/home',
	name: 'Home',
	component: () => import('../views/Home.vue'),
	meta: {
		title: "不一样的世界",
		headerShow: true, //是否显示头底部
		footerShow: true,
		iSkeepAlive: true//是否缓存
	},
},
{
	path: '/articleDetail/:id',
	name: 'articleDetail',
	component: () => import('../views/ArticleDetail.vue'),
	meta: {
		title: "瞧瞧",
		headerShow: true, //是否显示头底部
		footerShow: true,
		iSkeepAlive: false
	}
},
{
	path: '/Login',
	name: 'Login',
	component: () => import('../views/Login/Login.vue'),
	meta: {
		title: "登录",
		headerShow: false, //是否显示头底部
		footerShow: false,
		iSkeepAlive: false
	}
},
{
	path: '/Register',
	name: 'Register',
	component: () => import('../views/Register/Register.vue'),
	meta: {
		title: "踏上码神之路",
		headerShow: false, //是否显示头底部
		footerShow: false,
		iSkeepAlive: false
	}
},
{
	path: '/Category',
	name: 'Category',
	component: () => import('../views/Category/Category.vue'),
	meta: {
		title: "文章分类",
		headerShow: true, //是否显示头底部
		footerShow: true,
		iSkeepAlive: false
	}
},
{
	path: '/Pigeonhole',
	name: 'Pigeonhole',
	component: () => import('../views/Pigeonhole/Pigeonhole.vue'),
	meta: {
		title: "文章归档",
		headerShow: true, //是否显示头底部
		footerShow: true,
		iSkeepAlive: false
	}
},
{
	path: '/CategoryAndTag',
	name: 'CategoryAndTag',
	component: () => import('../views/CategoryAndTag/CategoryAndTag.vue'),
	meta: {
		title: "文章信息",
		headerShow: true, //是否显示头底部
		footerShow: true,
		iSkeepAlive: false
	}
},
{
	path: '/Barrage',
	name: 'Barrage',
	component: () => import('../views/Barrage/Barrage.vue'),
	meta: {
		title: "文章弹幕",
		headerShow: true, //是否显示头底部
		footerShow: false,
		iSkeepAlive: false
	}
},
{
	path: '/myArticle/:uid',
	name: 'myArticle',
	component: () => import('../views/myArticle/myArticle.vue'),
	meta: {
		title: "我的文章",
		headerShow: true, //是否显示头底部
		footerShow: true,
		iSkeepAlive: false
	}
},
{
	path: '/WriteArticle/:uid',
	name: 'WriteArticle',
	component: () => import('../views/WriteArticle/WriteArticle.vue'),
	meta: {
		title: "写文章",
		headerShow: true, //是否显示头底部
		footerShow: false,
		iSkeepAlive: false
	}
},
// UpdateArticle
{
	path: '/UpdateArticle',
	name: 'UpdateArticle',
	component: () => import('../views/UpdateArticle/UpdateArticle.vue'),
	meta: {
		title: "修改文章",
		headerShow: true, //是否显示头底部
		footerShow: false,
		iSkeepAlive: false
	}
},
// 消息界面
{
	path: '/Msg/:id',
	name: 'Msg',
	component: () => import('../views/Msg/Msg.vue'),
	meta: {
		title: "消息列表",
		headerShow: true, //是否显示头底部
		footerShow: false,
		iSkeepAlive: false
	}
},
// 网站资源
{
	path: '/resource',
	name: 'Msg',
	component: () => import('../views/WebsiteResources/WebsiteResources.vue'),
	meta: {
		title: "资源列表",
		headerShow: true, //是否显示头底部
		footerShow: false,
		iSkeepAlive: false
	}
},
// 资源详细
{
	path: '/resourceDetail',
	name: 'Detail',
	component: () => import('../views/WebsiteResources/ResourcesDetail.vue'),
	meta: {
		title: "资源详细",
		headerShow: true, //是否显示头底部
		footerShow: false,
		iSkeepAlive: false
	}
},
// 支付成功
{
	path: '/paySuccess',
	name: 'paySuccess',
	component: () => import('../views/paySuccess/PaySuccess.vue'),
	meta: {
		title: "支付成功",
		headerShow: true, //是否显示头底部
		footerShow: true,
		iSkeepAlive: false
	}
},

{
	path: '/:pathMatch(.*)*/',
	name: 'NotFound',
	component: () => import("../views/Notdefound/NotFound.vue"),
	meta: {
		title: "404",
		headerShow: false, //是否显示头底部
		footerShow: false,
		iSkeepAlive: false
	}
},
]



const router = new VueRouter({
	mode: 'hash',
	routes,
	scrollBehavior(to, from, savedPosition) {
		//x  y两个值
		return {
			y: 0
		}
	}
})

router.beforeEach((to, from, next) => {
	// 根据路由元信息设置文档标题
	window.document.title = to.meta.title || admin
	let UserName = store.state.UserInfo.nickname
	if (localStorage.getItem("TOKEN")) {
		if (to.path == "/Login") {
			next("/")
		} else {
			if (UserName) {
				next()
			} else {
				store.dispatch("getUserInfo")
				next()
			}
		}
	} else {
		next()
	}
})

export default router
